package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.service.AgentProductManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/agentProduct")
public class AgentProductManageController {

        @Autowired
        private AgentProductManageService service;
    /****
     * 经销商商品管理
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/cellProdctList")
    @ResponseBody
    public Dto cellProdctList(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.cellProdctList(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("添加失败","002");
        }
        return dto;
    }
    /****
     * 添加经销商商品
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/addCellProdct")
    @ResponseBody
    public Dto addCellProdct(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.addCellProdct(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("添加失败","002");
        }
        return dto;
    }

    /****
     * 添加经销商商品
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/addProductLbImg")
    @ResponseBody
    public Dto addProductLbImg(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.addProductLbImg(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("添加失败","002");
        }
        return dto;
    }

    /****
     * 更改商品信息
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/updateCellProdct")
    @ResponseBody
    public Dto updateCellProdct(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.updateCellProdct(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("添加失败","002");
        }
        return dto;
    }

    /****
     * 删除产品
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/deleteProdct")
    @ResponseBody
    public Dto deleteProdct(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=service.deleteProdct(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("添加失败","002");
        }
        return dto;
    }
}
